package com.example.renshiguanli.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.renshiguanli.mapper.UserMapper;
import com.example.renshiguanli.pojo.User;
import com.example.renshiguanli.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;
    @PostMapping("/user/login")
    public String userlogin(User user, Map<String, Object>map, HttpSession session){
        User u = userMapper.login(user);
        if(u==null){
            map.put("msg","用户名或密码错误");
            return "login";
        }
        else {
            session.setAttribute("loginUser",user.getUsername());
            return "redirect:/main.html";
        }
    }
}
